package com.beamfield.controller.manage.operator;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.beamfield.controller.common.BaseController;
import com.beamfield.enums.HttpResultEnum;
import com.beamfield.model.*;
import com.beamfield.modelVo.CertificateVo;
import com.beamfield.modelVo.OperatorTreeVo;
import com.beamfield.service.manage.operator.AttendService;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.annotations.Param;
import org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.FormulaEvaluator;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFFormulaEvaluator;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.commons.CommonsMultipartFile;
import org.springframework.web.servlet.ModelAndView;

import com.beamfield.common.ApiResult;
import com.beamfield.common.CommonUtils;
import com.beamfield.common.PageResult;
import com.beamfield.dictionary.code;
import com.beamfield.modelVo.SystemDictionaryDataVo;
import com.beamfield.service.manage.sys.DictonaryService;
import com.beamfield.service.manage.sys.FileService;
import com.beamfield.service.manage.operator.ManagerInfoService;
/**
 * 管理人员
 * @author zhaohh
 *
 */
@Controller
@RequestMapping("/cms/operator/managerInfo")
public class ManagerInfoController extends BaseController {

	@Value("${session.user}")
	private String user;

	@Value("${session.beam}")
	private String beam;

	@Resource
	ManagerInfoService managerInfoService;

	@Resource
	FileService fileService;

	@Resource
	DictonaryService dictonaryService;

	@Resource
	AttendService attendService;

	/**
	 * 组织架构图
	 * @return
	 */
	@RequestMapping("/organization")
	public ModelAndView organization() {
		return new ModelAndView();
	}

	@RequestMapping("/adjust")
	public ModelAndView adjust() {
		return new ModelAndView();
	}
    /**
     * 组织架构图-普通人员和特殊人员列表
     * @return
     */
    @RequestMapping("/organizationNS")
    public ModelAndView organizationNS(){
        return new ModelAndView();
    }
	/**
	 * 返回所有人员考勤信息列表
	 * @return
	 */
	@RequestMapping("/AllAttendList")
	public ModelAndView allAttendList() {
		return new ModelAndView();
	}

	/**
	 * 返回体检管理视图
	 * @return
	 */
	@RequestMapping("/medical")
	public ModelAndView medical() {
		return new ModelAndView();
	}

	/**
	 * 返回添加体检视图
	 *
	 * @return
	 */
	@RequestMapping("/addMedical")
	public ModelAndView addMedical() {
		return new ModelAndView();
	}

	@RequestMapping("/lookHealth")
	public ModelAndView lookHealth() {
		return new ModelAndView();
	}

	/**
	 * 返回健康管理视图
	 *
	 * @return
	 */
	@RequestMapping("/health")
	public ModelAndView health() {
		return new ModelAndView();
	}

	/**
	 * 返回添加健康视图
	 *
	 * @return
	 */
	@RequestMapping("/addHealth")
	public ModelAndView addHealth() {
		return new ModelAndView();
	}

	/**
	 * 返回健康管理视图
	 *
	 * @return
	 */
	@RequestMapping("/labour")
	public ModelAndView labour() {
		return new ModelAndView();
	}

	/**
	 * 返回添加健康视图
	 *
	 * @return
	 */
	@RequestMapping("/addLabour")
	public ModelAndView addLabour() {
		return new ModelAndView();
	}

	/**
	 * 返回健康详情视图
	 *
	 * @return
	 */
	@RequestMapping("/healthDetail")
	public ModelAndView healthDetail() {
		return new ModelAndView();
	}

	/**
	 * 获取组织架构图分析数据
	 *
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "/getOrganizationData", method = RequestMethod.GET)
	@ResponseBody
	public ApiResult getOrganizationData(HttpServletRequest request) {
		Long beamId = super.getBeamId(request);
		String beamName = super.getBeamName(request);
		return managerInfoService.getOrganizationData(beamId, beamName);
	}
	
	/**
	 * 获取组织架构的职位
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "/getJob", method = RequestMethod.GET)
	@ResponseBody
	public ApiResult getJob(HttpServletRequest request) {
		Long beamId = super.getBeamId(request);
		return managerInfoService.getJob(beamId);
	}
	
	/**
	 * 获取组织架构的职位
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "/getLabJob", method = RequestMethod.GET)
	@ResponseBody
	public ApiResult getLabJob(HttpServletRequest request) {
		Long beamId = super.getBeamId(request);
		return managerInfoService.getLabJob(beamId);
	}
	
	@RequestMapping(value = "/addLabJobOrBumen", method = RequestMethod.POST)
	@ResponseBody
	public ApiResult addLabJobOrBumen(HttpServletRequest request,String name,Integer type) {
		Long beamId = super.getBeamId(request);
		return managerInfoService.addLabJobOrBumen(beamId,name,type);
	}
	
	@RequestMapping(value = "/saveEdit", method = RequestMethod.POST)
	@ResponseBody
	public ApiResult saveEdit(HttpServletRequest request,String dataList) {
		return managerInfoService.saveEdit(dataList);
	}
	
	@RequestMapping(value = "/delData", method = RequestMethod.POST)
	@ResponseBody
	public ApiResult delData(HttpServletRequest request,Long id) {
		return managerInfoService.delData(id);
	}
	
	
	@RequestMapping(value = "/addJobOrBumen", method = RequestMethod.POST)
	@ResponseBody
	public ApiResult addJobOrBumen(HttpServletRequest request,String name,Integer type) {
		Long beamId = super.getBeamId(request);
		return managerInfoService.addJobOrBumen(beamId,name,type);
	}

	/**
	 * 获取所有职务
	 *
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "/getPresasg", method = RequestMethod.GET)
	@ResponseBody
	public ApiResult getPresasg(HttpServletRequest request) {
		Long beamId = super.getBeamId(request);
		String type = request.getParameter("type");
		if (StringUtils.isEmpty(type)) {
			return new ApiResult(HttpResultEnum.MIS_PARAM.getCode(), HttpResultEnum.MIS_PARAM.getMessage());
		}
		List<String> presasgList = managerInfoService.getPresasg(beamId, type);
		return new ApiResult(presasgList);
	}

	/**
	 * 保存人员请假信息
	 *
	 * @param leaveJson
	 * @param request
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/saveLeave", method = RequestMethod.POST)
	public ApiResult saveLeave(String leaveJson, HttpServletRequest request) {
		if (StringUtils.isEmpty(leaveJson)) {
			return new ApiResult(HttpResultEnum.MIS_PARAM.getCode(), HttpResultEnum.MIS_PARAM.getMessage());
		}
		Long beamId = super.getBeamId(request);
		Long userId = super.getUserId(request);
		try {
			Leave leave = JSON.parseObject(leaveJson, Leave.class);
			leave.setUpdater(userId);
			leave.setUpdatetime(new Date());
			return managerInfoService.saveLeave(leave,beamId,userId);
		} catch (Exception e) {
			e.printStackTrace();
			return new ApiResult(HttpResultEnum.EXCEPTION.getCode(), HttpResultEnum.EXCEPTION.getMessage());
		}
	}

	/**
	 * 获取所有人员信息
	 *
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "/allOperator", method = RequestMethod.GET)
	@ResponseBody
	public ApiResult getAllOperator(HttpServletRequest request) {
		long beamId = (long) request.getSession().getAttribute(beam);
		String workdept = request.getParameter("workdept");
		String group = request.getParameter("group");
		List<ManagerInfo> managerInfoList = managerInfoService.getAllOperatorInfo(beamId, workdept, group);
		ApiResult apiResult = new ApiResult();
		apiResult.setResult(managerInfoList);
		return apiResult;
	}

	/**
	 * 获取人员树形结构数据
	 * operatorRange人员范围 workdept:查看所有部门 group:查找所有班组的 special:查找特殊人员 normal:普通人员
	 *
	 * @param request
	 * @return
	 */
	@RequestMapping("/getOperatorTreeData")
	@ResponseBody
	public ApiResult getOperatorTreeData(HttpServletRequest request) {
		Long beamId = super.getBeamId(request);
		String operatorRange = request.getParameter("operatorRange");
		List<OperatorTreeVo> operatorTreeData = managerInfoService.getOperatorTreeData(beamId, operatorRange);
		return new ApiResult(operatorTreeData);
	}


	@RequestMapping("/getOperatorByEcode")
	@ResponseBody
	public ApiResult getOperatorByEcode(HttpServletRequest request, String ecode) {
		Long beamId = super.getBeamId(request);
		NormalOperator operatorByEcode = managerInfoService.getOperatorByEcode(beamId, ecode);
		ApiResult apiResult = new ApiResult();
		apiResult.setResult(operatorByEcode);
		return apiResult;
	}

	/**
	 * 证书上传页面
	 *
	 * @return
	 */
	@RequestMapping("/uploadCertificate")
	public ModelAndView uploadCertificate() {
		return new ModelAndView();
	}

	/**
	 * 获取特殊和普通人员列表
	 *
	 * @param offset
	 * @param limit
	 * @param ecode
	 * @param name
	 * @return
	 */
	@RequestMapping("/getNormalAndSpecialOperatorList")
	@ResponseBody
	public PageResult mergeOperatorList(Integer offset, Integer limit, String ecode, String name, String presasg, String group, HttpSession session) {
		Long beam_id = (Long) session.getAttribute(beam);
		return managerInfoService.mergeOperatorList(offset, limit, ecode, name, beam_id, presasg, group);
	}


	/**
	 * 人员管理页面
	 *
	 * @return
	 */
	@RequestMapping("/managerInfo")
	public ModelAndView managerInfo() {
		return new ModelAndView();
	}

	/**
	 * 获取管理人员列表
	 *
	 * @param offset
	 * @param limit
	 * @param ecode
	 * @param name
	 * @return
	 */
	@RequestMapping("/getManagerInfoList")
	@ResponseBody
	public PageResult getManagerInfoList(Integer offset, Integer limit, String ecode, String name, String presasg, String work, HttpSession session) {
		Long beam_id = (Long) session.getAttribute(beam);
		return managerInfoService.getManagerInfoList(offset, limit, ecode, name, beam_id, presasg, work);
	}

	/**
	 * 编辑或新增页面
	 *
	 * @return
	 */
	@RequestMapping("/editManagerInfo")
	public ModelAndView editManagerInfo() {
		ModelAndView modelAndView = new ModelAndView();

		return modelAndView;
	}

	@RequestMapping("/getEditInfo")
	@ResponseBody
	public ApiResult getEditInfo(Long id, HttpSession session) {
		ApiResult apiResult = new ApiResult();
		long beamId = (long) session.getAttribute(beam);

		Map<String, Object> map = new HashMap<String, Object>();
		ManagerInfo managerInfo = managerInfoService.getManagerInfoById(id);
		if (managerInfo != null) {
			if (managerInfo.getAvatar() != null) {
				managerInfo.setPic_url(CommonUtils.getFielUrl(fileService.getFileById(managerInfo.getAvatar())));
			}

			if (StringUtils.isNotBlank(managerInfo.getExtend3())) {
				managerInfo.setExtend3(CommonUtils.getFielUrl(fileService.getFileById(Long.parseLong(managerInfo.getExtend3()))));
			}
			if (StringUtils.isNotBlank(managerInfo.getExtend4())) {
				managerInfo.setExtend4(CommonUtils.getFielUrl(fileService.getFileById(Long.parseLong(managerInfo.getExtend4()))));
			}
			if (managerInfo.getQrcode() != null) {
				managerInfo.setQr_url(CommonUtils.getQrUrl(fileService.getFileById(managerInfo.getQrcode())));
			}
		}
		List<SystemDictionaryDataVo> department = dictonaryService.getDicByCode(code.department, beamId);
		List<SystemDictionaryDataVo> education = dictonaryService.getDicByCode(code.education, beamId);
		List<SystemDictionaryDataVo> health = dictonaryService.getDicByCode(code.health, beamId);
		List<SystemDictionaryDataVo> policital = dictonaryService.getDicByCode(code.policital, beamId);
		List<SystemDictionaryDataVo> sex = dictonaryService.getDicByCode(code.sex, beamId);
		List<SystemDictionaryDataVo> volk = dictonaryService.getDicByCode(code.volk, beamId);
		map.put("department", department);
		map.put("education", education);
		map.put("health", health);
		map.put("policital", policital);
		map.put("sex", sex);
		map.put("volk", volk);
		map.put("managerInfo", managerInfo);
		apiResult.setResult(map);
		return apiResult;
	}

	/**
	 * 详情页面
	 *
	 * @param id
	 * @return
	 */
	@RequestMapping("/managerInfoDetail")
	public ModelAndView managerInfoDetail(Long id) {
		ModelAndView modelAndView = new ModelAndView();
		return modelAndView;
	}

	@RequestMapping("/getDetailInfo")
	@ResponseBody
	public ApiResult getDetailInfo(Long id, HttpSession session) {
		ApiResult apiResult = new ApiResult();
		long beamId = (long) session.getAttribute(beam);

		Map<String, Object> map = new HashMap<String, Object>();
		ManagerInfo managerInfo = managerInfoService.getManagerInfoById(id);
		if (managerInfo != null) {
		    if(managerInfo.getAvatar() != null){
                managerInfo.setPic_url(CommonUtils.getFielUrl(fileService.getFileById(managerInfo.getAvatar())));
            }

			if (managerInfo.getQrcode() != null) {
				managerInfo.setQr_url(CommonUtils.getQrUrl(fileService.getFileById(managerInfo.getQrcode())));
			}


			SystemDictionaryData sex = managerInfoService.selectByCode(managerInfo.getGender(), beamId);

			if (sex != null) {
				managerInfo.setGender(sex.getName());
			}

			SystemDictionaryData workdept = managerInfoService.selectByCode(managerInfo.getWorkdept(), beamId);

			if (workdept != null) {
				managerInfo.setWorkdept(workdept.getName());
			}

			SystemDictionaryData volk = managerInfoService.selectByCode(managerInfo.getNation(), beamId);

			if (volk != null) {
				managerInfo.setNation(volk.getName());
			}

			SystemDictionaryData political = managerInfoService.selectByCode(managerInfo.getPolitical(), beamId);

			if (political != null) {
				managerInfo.setPolitical(political.getName());
			}

			SystemDictionaryData health = managerInfoService.selectByCode(managerInfo.getHealth(), beamId);

			if (health != null) {
				managerInfo.setHealth(health.getName());
			}

			SystemDictionaryData education = managerInfoService.selectByCode(managerInfo.getEducation(), beamId);

			if (education != null) {
				managerInfo.setEducation(education.getName());
			}

			SystemDictionaryData relation = managerInfoService.selectByCode(managerInfo.getRelation(), beamId);

			if (relation != null) {
				managerInfo.setRelation(relation.getName());
			}
		}
		List<SystemDictionaryDataVo> department = dictonaryService.getDicByCode(code.department, beamId);
		List<SystemDictionaryDataVo> education = dictonaryService.getDicByCode(code.education, beamId);
		List<SystemDictionaryDataVo> health = dictonaryService.getDicByCode(code.health, beamId);
		List<SystemDictionaryDataVo> policital = dictonaryService.getDicByCode(code.policital, beamId);
		List<SystemDictionaryDataVo> sex = dictonaryService.getDicByCode(code.sex, beamId);
		List<SystemDictionaryDataVo> volk = dictonaryService.getDicByCode(code.volk, beamId);
		map.put("department", department);
		map.put("education", education);
		map.put("health", health);
		map.put("policital", policital);
		map.put("sex", sex);
		map.put("volk", volk);
		map.put("managerInfo", managerInfo);
		apiResult.setResult(map);
		return apiResult;
	}


	/**
	 * 新增或编辑
	 *
	 * @param managerInfo
	 * @return
	 */
	@RequestMapping("/doEditManagerInfo")
	@ResponseBody
	public ApiResult doEditManagerInfo(ManagerInfo managerInfo, HttpSession session) {
		Long user_id = (Long) session.getAttribute(user);
		Long beam_id = (Long) session.getAttribute(beam);

		managerInfo.setUpdater(user_id);
		managerInfo.setUpdatetime(new Date());
		managerInfo.setBeam_id(beam_id);

		//身份证唯一性校验
		Integer countIDCard = managerInfoService.checkCountManagerInfoIDCard(managerInfo.getIdentity(), managerInfo.getManager_id());
		Integer countIDCard2 = managerInfoService.checkCountNormalOperatorIDCard(managerInfo.getIdentity(), managerInfo.getManager_id());
		Integer countIDCard3 = managerInfoService.checkCountSpecialOperatorIDCard(managerInfo.getIdentity(), managerInfo.getManager_id());

		Integer namenum = managerInfoService.checkCountManagerInfoName(managerInfo.getName(), managerInfo.getManager_id(),beam_id);
		if (namenum > 0) {
			return new ApiResult("1", "姓名重复！");
		}
		if (countIDCard+countIDCard2+countIDCard3 > 0) {
			return new ApiResult("1", "身份证号重复！");
		}

		try {
			//新增
			if (managerInfo.getManager_id() == null) {
				Integer count = managerInfoService.getManagerInfoCount();
				DecimalFormat format = new DecimalFormat("0000");
				String code = format.format(count + 1);
				managerInfo.setEcode("01" + code);
				managerInfo.setOperator(user_id);
				managerInfo.setAddtime(new Date());
				managerInfo.setDelflag(0);
				managerInfo.setAdjust(0);
				managerInfoService.insertManagerInfo(managerInfo);
			}
			//编辑
			if (managerInfo.getManager_id() != null) {
				managerInfoService.updateManagerInfo(managerInfo);
			}
		} catch (Exception e) {
			e.printStackTrace();
			return new ApiResult("1", "服务器异常！");
		}

		return new ApiResult("2", "成功！");
	}

	/**
	 * 删除
	 *
	 * @param id
	 * @param session
	 * @return
	 */
	@RequestMapping("/delManagerInfo")
	@ResponseBody
	public ApiResult delManagerInfo(Long id, HttpSession session) {
		ManagerInfo managerInfo = managerInfoService.getManagerInfoById(id);
		if (managerInfo == null) {
			return new ApiResult("1", "删除失败，查不到该数据!");
		}
		Long user_id = (Long) session.getAttribute(user);
		managerInfo.setUpdater(user_id);
		managerInfo.setUpdatetime(new Date());
		managerInfo.setDelflag(1);
		try {
			managerInfoService.updateManagerInfo(managerInfo);
		} catch (Exception e) {
			e.printStackTrace();
			return new ApiResult("1", "删除失败，服务器异常!");
		}
		return new ApiResult("2", "成功!");
	}
	/**
	 * 人员导入
	 * @param request
	 * @param multipartFile
	 * @return
	 */
	@RequestMapping(value = "/importPeople", method = RequestMethod.POST)
	@ResponseBody
	public ApiResult importManager(HttpServletRequest request, @RequestParam("excelFile") MultipartFile multipartFile, String type) {
		Long userId = super.getUserId(request);
		Long beamId = super.getBeamId(request);

		if (multipartFile == null) {
			return new ApiResult(HttpResultEnum.MIS_PARAM.getCode(), HttpResultEnum.MIS_PARAM.getMessage());
		}
		try {
			long fileId = super.saveFile((CommonsMultipartFile) multipartFile);
			InputStream in = multipartFile.getInputStream();
			byte[] data = IOUtils.toByteArray(in);
			Workbook wb = null;
			FormulaEvaluator formulaEvaluator;
			try {
				wb = new HSSFWorkbook(new ByteArrayInputStream(data));
				formulaEvaluator = new HSSFFormulaEvaluator((HSSFWorkbook) wb);
			} catch (Exception e) {
				wb = new XSSFWorkbook(new ByteArrayInputStream(data));
				formulaEvaluator = new XSSFFormulaEvaluator((XSSFWorkbook) wb);
			}
			switch (type){
			    //管理人员导入
				case "1":return managerInfoService.importManager(wb,fileId,userId,beamId,formulaEvaluator,null);
				//劳务人员导入
				case "2":return managerInfoService.importNormal(wb,fileId,userId,beamId,formulaEvaluator);
				//技术工人导入
				case "3":return managerInfoService.importSpecial(wb,fileId,userId,beamId,formulaEvaluator);
				//试验室人员导入
				case "4":return managerInfoService.importManager(wb,fileId,userId,beamId,formulaEvaluator,"990107");
				//拌和站人员导入
				case "5":return managerInfoService.importManager(wb,fileId,userId,beamId,formulaEvaluator,"990110");
				default:return new ApiResult(HttpResultEnum.MIS_PARAM.getCode(), HttpResultEnum.MIS_PARAM.getMessage());
			}
		} catch (Exception e) {
			e.printStackTrace();
			return new ApiResult(HttpResultEnum.EXCEPTION.getCode(), HttpResultEnum.EXCEPTION.getMessage());
		}
	}
	/**
	 * 管理人员的培训列表
	 *
	 * @param offset
	 * @param limit
	 * @param manager_id
	 * @param session
	 * @return
	 */
	@RequestMapping("/getDetailManagerTrainList")
	@ResponseBody
	public PageResult getDetailManagerTrainList(Integer offset, Integer limit, Long manager_id, HttpSession session) {
		return managerInfoService.getDetailManagerTrainList(offset, limit, manager_id);
	}

	/**
	 * 项目管理人员考勤页面
	 *
	 * @return
	 */
	@RequestMapping("/managerInfoAttend")
	public ModelAndView managerInfoAttend() {
		ModelAndView modelAndView = new ModelAndView();
		return modelAndView;
	}

	/**
	 * 管理人员的考勤列表
	 *
	 * @param offset
	 * @param limit
	 * @param name
	 * @param time
	 * @return
	 */
	@RequestMapping("/getManagerInfoAttendList")
	@ResponseBody
	public PageResult getManagerInfoAttendList(Integer offset, Integer limit, String name, String time, String workdept, HttpSession session) {
		Long beam_id = (Long) session.getAttribute(beam);
		return managerInfoService.getManagerInfoAttendList(offset, limit, name, time, workdept, beam_id);
	}

	/**
	 * 全体人员的考勤列表
	 *
	 * @param offset
	 * @param limit
	 * @param name
	 * @param time
	 * @return
	 */
	@RequestMapping("/getAllAttendList")
	@ResponseBody
	public PageResult getAllAttendList(Integer offset, Integer limit, String name, String time, String workdept, HttpSession session) {
		Long beam_id = (Long) session.getAttribute(beam);
		return managerInfoService.getAllAttendList(offset, limit, name, time, workdept, beam_id);
	}

	/**
	 * 全体人员信息
	 *
	 * @param offset
	 * @param limit
	 * @param ecode
	 * @param name
	 * @return
	 */
	@RequestMapping("/getAllOperator")
	@ResponseBody
	public PageResult getAllOperator(Integer offset, Integer limit, String name, String presasg, HttpSession session, String ecode) {
		Long beam_id = (Long) session.getAttribute(beam);
		return managerInfoService.selectAllUser(beam_id, name, ecode, presasg, offset, limit);
	}

	/**
	 * 所有考勤列表
	 *
	 * @param offset
	 * @param limit
	 * @param name
	 * @param time
	 * @param workdept
	 * @param session
	 * @return
	 */
	@RequestMapping("/getAllOperatorAttendList")
	@ResponseBody
	public PageResult getAllOperatorAttendList(Integer offset, Integer limit, String name, String time, String workdept, HttpSession session) {
		Long beam_id = (Long) session.getAttribute(beam);
		return managerInfoService.getAllOperatorAttendList(offset, limit, name, time, workdept, beam_id);
	}

	/**
	 * 项目管理人员考勤页面
	 *
	 * @return
	 */
	@RequestMapping("/attendDetail")
	public ModelAndView attendDetail() {
		ModelAndView modelAndView = new ModelAndView();
		return modelAndView;
	}

	/**
	 * 管理人员的考勤明细
	 *
	 * @param offset
	 * @param limit
	 * @param name
	 * @param year
	 * @return 返回的属性中，1表示正常打卡，无值表示未打卡或者打卡异常。
	 */
	@RequestMapping("/getManagerInfoAttendDetailList")
	@ResponseBody
	public PageResult getManagerInfoAttendDetailList(Integer offset, Integer limit, String name, String year, HttpSession session) {
		long beam_id = (long) session.getAttribute(beam);
//		return managerInfoService.getManagerInfoAttendDetailList(offset, limit, name, year, beam_id);
		return attendService.getPersonalAttendList(offset, limit, name, year, beam_id);
	}

	/**
	 * 获取部门信息
	 *
	 * @return
	 */
	@RequestMapping("/getWorkDept")
	@ResponseBody
	public ApiResult getWorkDept(HttpSession session) {
		long beam_id = (long) session.getAttribute(beam);
		return managerInfoService.getWorkDept(beam_id);
	}

	/**
	 * 获取班组信息
	 *
	 * @return
	 */
	@RequestMapping("/getGroup")
	@ResponseBody
	public ApiResult getGroup(HttpSession session) {
		long beam_id = (long) session.getAttribute(beam);
		return managerInfoService.getGroup(beam_id);
	}

	/**
	 * 导出项目管理人员数据
	 *
	 * @param response
	 * @param ecode
	 * @param name
	 * @param session
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/exportManagerInfoDetail")
	@ResponseBody
	public String exportDetail(HttpServletResponse response, String ecode, String name, String work, String presasg, HttpSession session) throws Exception {
		Long beam_id = (Long) session.getAttribute(beam);
		String apiResult = managerInfoService.exportManagerInfoDetail(ecode, response, name, beam_id, work, presasg);
		return apiResult;
	}

	/**
	 * 上传证书
	 *
	 * @param multipartFile
	 * @return
	 */
	@RequestMapping(value = "/upload", method = RequestMethod.POST)
	@ResponseBody
	public ApiResult upload(@RequestParam(value = "certificateFile") MultipartFile multipartFile) {
		long commeFileId = 0;
		try {
			commeFileId = super.saveFile((CommonsMultipartFile) multipartFile);
		} catch (Exception e) {
			e.printStackTrace();
			return new ApiResult(HttpResultEnum.EXCEPTION.getCode(), HttpResultEnum.EXCEPTION.getMessage());
		}
		return new ApiResult(commeFileId);
	}

	/**
	 * 保存证书
	 *
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "/saveCertificate", method = RequestMethod.POST)
	@ResponseBody
	public ApiResult saveCertificate(HttpServletRequest request) {
		Long beamId = super.getBeamId(request);
		Long userId = super.getUserId(request);
		String certificateListJson = request.getParameter("certificateListJson");
		String ecode = request.getParameter("ecode");
		if (StringUtils.isEmpty(certificateListJson) || StringUtils.isEmpty(ecode)) {
			return new ApiResult(HttpResultEnum.MIS_PARAM.getCode(), HttpResultEnum.MIS_PARAM.getMessage());
		}
		try {
			List<HashMap> certificateList = JSON.parseArray(certificateListJson, HashMap.class);
			return managerInfoService.saveCertificate(beamId, userId, certificateList, ecode);
		} catch (Exception e) {
			e.printStackTrace();
			return new ApiResult(HttpResultEnum.EXCEPTION.getCode(), HttpResultEnum.EXCEPTION.getMessage());
		}
	}

	/**
	 * 获取证书数据
	 *
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "/readCertificateData", method = RequestMethod.GET)
	@ResponseBody
	public PageResult readCertificateData(HttpServletRequest request) {
		long beamId = super.getBeamId(request);
		String offset = request.getParameter("offset");
		String limit = request.getParameter("limit");
		String ecode = request.getParameter("ecode");
		if (StringUtils.isEmpty(ecode)) {
			return null;
		}
		List<CertificateVo> certificateList = managerInfoService.readCertificateData(beamId, offset, limit, ecode);
		long total = managerInfoService.countCertificateData(beamId, ecode);
		return new PageResult(total, CommonUtils.parseLong(offset, 0l), certificateList);
	}

	/**
	 * 继续教育页面
	 *
	 * @return
	 */
	@RequestMapping(value = "/reeducation")
	public ModelAndView reeducation() {
		return new ModelAndView();
	}

	/**
	 * 保存再教育
	 *
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "/saveReeducation", method = RequestMethod.POST)
	@ResponseBody
	public ApiResult saveReeducation(HttpServletRequest request) {
		Long beamId = super.getBeamId(request);
		Long userId = super.getUserId(request);
		String reeducationJson = request.getParameter("reeducationJson");
		if (StringUtils.isEmpty(reeducationJson)) {
			return new ApiResult(HttpResultEnum.MIS_PARAM.getCode(), HttpResultEnum.MIS_PARAM.getMessage());
		}
		try {
			Reeducation reeducation = JSON.parseObject(reeducationJson, Reeducation.class);
			return managerInfoService.saveReeducation(beamId, userId, reeducation);
		} catch (Exception e) {
			e.printStackTrace();
			return new ApiResult(HttpResultEnum.EXCEPTION.getCode(), HttpResultEnum.EXCEPTION.getMessage());
		}
	}

	/**
	 * 批量保存再教育
	 *
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "/saveBatchReeducation", method = RequestMethod.POST)
	@ResponseBody
	public ApiResult saveBatchReeducation(HttpServletRequest request) {
		Long beamId = super.getBeamId(request);
		Long userId = super.getUserId(request);
		String reeducationJson = request.getParameter("reeducationJson");
		if (StringUtils.isEmpty(reeducationJson)) {
			return new ApiResult(HttpResultEnum.MIS_PARAM.getCode(), HttpResultEnum.MIS_PARAM.getMessage());
		}
		try {
			Reeducation reeducation = JSON.parseObject(reeducationJson, Reeducation.class);
			return managerInfoService.saveBatchReeducation(beamId, userId, reeducation);
		} catch (Exception e) {
			e.printStackTrace();
			return new ApiResult(HttpResultEnum.EXCEPTION.getCode(), HttpResultEnum.EXCEPTION.getMessage());
		}
	}

	/**
	 * 删除再教育
	 *
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "/delReeducation", method = RequestMethod.POST)
	@ResponseBody
	public ApiResult delReeducation(HttpServletRequest request) {
		Long userId = super.getUserId(request);
		String id = request.getParameter("id");
		if (StringUtils.isEmpty(id)) {
			return new ApiResult(HttpResultEnum.MIS_PARAM.getCode(), HttpResultEnum.MIS_PARAM.getMessage());
		}
		try {
			return managerInfoService.delReeducation(userId, id);
		} catch (Exception e) {
			e.printStackTrace();
			return new ApiResult(HttpResultEnum.EXCEPTION.getCode(), HttpResultEnum.EXCEPTION.getMessage());
		}
	}

	/**
	 * 获取再教育数据
	 *
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "/readReeducationData", method = RequestMethod.GET)
	@ResponseBody
	public PageResult readReeducationData(HttpServletRequest request) {
		long beamId = super.getBeamId(request);
		String offset = request.getParameter("offset");
		String limit = request.getParameter("limit");
		String ecode = request.getParameter("ecode");
		if (StringUtils.isEmpty(ecode)) {
			return null;
		}
		List<Reeducation> reeducationList = managerInfoService.readReeducationData(beamId, offset, limit, ecode);
		long total = managerInfoService.countReeducationData(beamId, ecode);
		return new PageResult(total, CommonUtils.parseLong(offset, 0L), reeducationList);
	}

	/**
	 * 获取所有人员再教育数据，不分人员
	 *
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "/readAllReeducationData", method = RequestMethod.GET)
	@ResponseBody
	public PageResult readAllReeducationData(HttpServletRequest request) {
		long beamId = super.getBeamId(request);
		String offset = request.getParameter("offset");
		String limit = request.getParameter("limit");
		String name = request.getParameter("name");
		String workdept = request.getParameter("workdept");
		String edu_content = request.getParameter("edu_content");
		String edu_date = request.getParameter("edu_date");
		List<Reeducation> reeducationList = managerInfoService.readAllReeducationData(beamId, offset, limit, name, workdept, edu_content, edu_date);
		long total = managerInfoService.countAllReeducationData(beamId, name, workdept, edu_content, edu_date);
		return new PageResult(total, CommonUtils.parseLong(offset, 0L), reeducationList);
	}

	/**
	 * 请假管理页面
	 *
	 * @return
	 */
	@RequestMapping(value = "/leave")
	public ModelAndView leave() {
		return new ModelAndView();
	}
	@RequestMapping(value = "/businessTrip")
	public ModelAndView businessTrip() {
		return new ModelAndView();
	}

	/**
	 * 获取请假数据
	 *
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "/readLeaveData", method = RequestMethod.GET)
	@ResponseBody
	public PageResult readLeaveData(HttpServletRequest request) {
		long beamId = super.getBeamId(request);
		String offset = request.getParameter("offset");
		String limit = request.getParameter("limit");
		String type = request.getParameter("type");
		String name = request.getParameter("name");
		String workdept = request.getParameter("workdept");
//		if(StringUtils.isEmpty(type)){
//			return null;
//		}
		List<Leave> leaveList = managerInfoService.readLeaveData(beamId, offset, limit, type, name, workdept);
		long total = managerInfoService.countLeaveData(beamId, type, name, workdept);
		return new PageResult(total, CommonUtils.parseLong(offset, 0L), leaveList);
	}

	/**
	 * 删除请假
	 *
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "/delLeave", method = RequestMethod.POST)
	@ResponseBody
	public ApiResult delLeave(HttpServletRequest request) {
	    Long beamId = super.getBeamId(request);
	    Long userId = super.getUserId(request);

		String id = request.getParameter("id");
		if (StringUtils.isEmpty(id)) {
			return new ApiResult(HttpResultEnum.MIS_PARAM.getCode(), HttpResultEnum.MIS_PARAM.getMessage());
		}
		try {
			return managerInfoService.delLeave(id,beamId,userId);
		} catch (Exception e) {
			e.printStackTrace();
			return new ApiResult(HttpResultEnum.EXCEPTION.getCode(), HttpResultEnum.EXCEPTION.getMessage());
		}
	}

	/**
	 * 保存人员履历
	 *
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "/saveResume", method = RequestMethod.POST)
	@ResponseBody
	public ApiResult saveResume(HttpServletRequest request) {
		Long beamId = super.getBeamId(request);
		Long userId = super.getUserId(request);
		String resumeJson = request.getParameter("resumeJson");
		if (StringUtils.isEmpty(resumeJson)) {
			return new ApiResult(HttpResultEnum.MIS_PARAM.getCode(), HttpResultEnum.MIS_PARAM.getMessage());
		}
		try {
			Resume resume = JSON.parseObject(resumeJson, Resume.class);
			return managerInfoService.saveResume(beamId, userId, resume);
		} catch (Exception e) {
			e.printStackTrace();
			return new ApiResult(HttpResultEnum.EXCEPTION.getCode(), HttpResultEnum.EXCEPTION.getMessage());
		}
	}

	/**
	 * 删除人员履历
	 *
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "/delResume", method = RequestMethod.POST)
	@ResponseBody
	public ApiResult delResume(HttpServletRequest request) {
		Long userId = super.getUserId(request);
		String id = request.getParameter("id");
		if (StringUtils.isEmpty(id)) {
			return new ApiResult(HttpResultEnum.MIS_PARAM.getCode(), HttpResultEnum.MIS_PARAM.getMessage());
		}
		try {
			return managerInfoService.delResume(userId, id);
		} catch (Exception e) {
			e.printStackTrace();
			return new ApiResult(HttpResultEnum.EXCEPTION.getCode(), HttpResultEnum.EXCEPTION.getMessage());
		}
	}

	/**
	 * 获取人员履历数据
	 *
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "/readResumeData", method = RequestMethod.GET)
	@ResponseBody
	public PageResult readResumeData(HttpServletRequest request) {
		long beamId = super.getBeamId(request);
		String offset = request.getParameter("offset");
		String limit = request.getParameter("limit");
		String ecode = request.getParameter("ecode");
		if (StringUtils.isEmpty(ecode)) {
			return null;
		}
		List<Resume> resumeList = managerInfoService.readResumeData(beamId, offset, limit, ecode);
		long total = managerInfoService.countResumeData(beamId, ecode);
		return new PageResult(total, CommonUtils.parseLong(offset, 0L), resumeList);
	}
	
	/**
	 * 获取荣誉记录数据
	 *
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "/readHonorData", method = RequestMethod.GET)
	@ResponseBody
	public PageResult readHonorData(HttpServletRequest request) {
		long beamId = super.getBeamId(request);
		String offset = request.getParameter("offset");
		String limit = request.getParameter("limit");
		String ecode = request.getParameter("ecode");
		if (StringUtils.isEmpty(ecode)) {
			return null;
		}
		List<HonorInfo> resumeList = managerInfoService.readHonorData(beamId, offset, limit, ecode);
		long total = managerInfoService.countHonorData(beamId, ecode);
		return new PageResult(total, CommonUtils.parseLong(offset, 0L), resumeList);
	}
	
	/**
	 * 保存荣誉记录
	 *
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "/saveHonor", method = RequestMethod.POST)
	@ResponseBody
	public ApiResult saveHonor(HttpServletRequest request) {
		Long beamId = super.getBeamId(request);
		Long userId = super.getUserId(request);
		String honorJson = request.getParameter("honorJson");
		if (StringUtils.isEmpty(honorJson)) {
			return new ApiResult(HttpResultEnum.MIS_PARAM.getCode(), HttpResultEnum.MIS_PARAM.getMessage());
		}
		try {
			HonorInfo honor = JSON.parseObject(honorJson, HonorInfo.class);
			return managerInfoService.saveHonor(beamId, userId, honor);
		} catch (Exception e) {
			e.printStackTrace();
			return new ApiResult(HttpResultEnum.EXCEPTION.getCode(), HttpResultEnum.EXCEPTION.getMessage());
		}
	}

	/**
	 * 删除荣誉记录
	 *
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "/delHonor", method = RequestMethod.POST)
	@ResponseBody
	public ApiResult delHonor(HttpServletRequest request) {
		Long userId = super.getUserId(request);
		String id = request.getParameter("id");
		if (StringUtils.isEmpty(id)) {
			return new ApiResult(HttpResultEnum.MIS_PARAM.getCode(), HttpResultEnum.MIS_PARAM.getMessage());
		}
		try {
			return managerInfoService.delHonor(userId, id);
		} catch (Exception e) {
			e.printStackTrace();
			return new ApiResult(HttpResultEnum.EXCEPTION.getCode(), HttpResultEnum.EXCEPTION.getMessage());
		}
	}

	/**
	 * 薪资页面
	 *
	 * @return
	 */
	@RequestMapping(value = "/payment")
	public ModelAndView payment() {
		return new ModelAndView();
	}

	/**
	 * 人员薪资导入
	 *
	 * @param request
	 * @param multipartFile
	 * @return
	 */
	@RequestMapping(value = "/importPayment", method = RequestMethod.POST)
	@ResponseBody
	public ApiResult initProject(HttpServletRequest request, @RequestParam("excelFile") MultipartFile multipartFile) {
		Long userId = super.getUserId(request);
		Long beamId = super.getBeamId(request);
		String type = request.getParameter("type");
		if (StringUtils.isEmpty(type) || multipartFile == null) {
			return new ApiResult(HttpResultEnum.MIS_PARAM.getCode(), HttpResultEnum.MIS_PARAM.getMessage());
		}
		int result = 0;
		try {
			long fileId = super.saveFile((CommonsMultipartFile) multipartFile);
			InputStream in = multipartFile.getInputStream();
			byte[] data = IOUtils.toByteArray(in);
			Workbook wb = null;
			FormulaEvaluator formulaEvaluator;
			try {
				wb = new HSSFWorkbook(new ByteArrayInputStream(data));
				formulaEvaluator = new HSSFFormulaEvaluator((HSSFWorkbook) wb);
			} catch (Exception e) {
				wb = new XSSFWorkbook(new ByteArrayInputStream(data));
				formulaEvaluator = new XSSFFormulaEvaluator((XSSFWorkbook) wb);
			}
			result = managerInfoService.importPayment(wb, fileId, type, userId, beamId, formulaEvaluator);
		} catch (Exception e) {
			e.printStackTrace();
			return new ApiResult(HttpResultEnum.EXCEPTION.getCode(), HttpResultEnum.EXCEPTION.getMessage());
		}
		if (result == 0) {
			return new ApiResult(HttpResultEnum.EXCEPTION.getCode(), HttpResultEnum.EXCEPTION.getMessage());
		} else {
			return new ApiResult(HttpResultEnum.SUCCESS.getCode(), "导入成功");
		}
	}

	/**
	 * 获取人员薪酬数据
	 *
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "/readPayment", method = RequestMethod.GET)
	@ResponseBody
	public PageResult readPayment(HttpServletRequest request) {
		long beamId = super.getBeamId(request);
		String offset = request.getParameter("offset");
		String limit = request.getParameter("limit");
		String type = request.getParameter("type");
		if (StringUtils.isEmpty(type)) {
			return null;
		}
		String name = request.getParameter("name");
		String paymentDate = request.getParameter("paymentDate");
		if ("1".equals(type)) {
			List<ManagerPayment> managerPayments = managerInfoService.readPaymentOfManager(beamId, offset, limit, name, paymentDate);
			long total = managerInfoService.countPaymentOfManager(beamId, name, paymentDate);
			return new PageResult(total, CommonUtils.parseLong(offset, 0L), managerPayments);
		} else {
			List<NormalPayment> normalPayments = managerInfoService.readPaymentOfNormal(beamId, offset, limit, name, paymentDate);
			long total = managerInfoService.countPaymentOfNormal(beamId, name, paymentDate);
			return new PageResult(total, CommonUtils.parseLong(offset, 0L), normalPayments);
		}
	}

	/**
	 * 新增或更新体检信息
	 *
	 * @return
	 */
	@RequestMapping(value = "saveMedical")
	@ResponseBody
	public ApiResult saveMedical(HttpServletRequest request, String object, String medical_date2) {
		long beamId = super.getBeamId(request);
		long userId = super.getUserId(request);
		SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
		Medical medical = JSON.parseObject(object, Medical.class);
		try {
			Date parse = simpleDateFormat.parse(medical_date2);
			medical.setMedical_date(parse);

		} catch (ParseException e) {
			e.printStackTrace();
			return new ApiResult("500", "请选择正确的日期");
		}
		ApiResult apiResult = managerInfoService.saveMedical(medical, beamId, userId);
		return apiResult;
	}

	/**
	 * 新增或更新健康信息
	 *
	 * @return
	 */
	@RequestMapping(value = "saveHealth")
	@ResponseBody
	public ApiResult saveHealth(HttpServletRequest request, String object, String occupational) {
		long beamId = super.getBeamId(request);
		long userId = super.getUserId(request);
		Health health = JSON.parseObject(object, Health.class);
		health.setOccupational(occupational);
		ApiResult apiResult = managerInfoService.saveHealth(health, beamId, userId);
		return apiResult;
	}

	/**
	 * 新增或更新保险信息
	 *
	 * @return
	 */
	@RequestMapping(value = "saveLabour")
	@ResponseBody
	public ApiResult saveLabour(HttpServletRequest request, String object, String labor_type) {
		long beamId = super.getBeamId(request);
		long userId = super.getUserId(request);
		Labour labour = JSON.parseObject(object, Labour.class);
		labour.setLabor_type(labor_type);
		ApiResult apiResult = managerInfoService.saveLabour(labour, beamId, userId);
		return apiResult;
	}

	/**
	 * 删除人员保险
	 *
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "/delLobour", method = RequestMethod.POST)
	@ResponseBody
	public ApiResult delLobour(HttpServletRequest request) {
		String id = request.getParameter("id");
		if (StringUtils.isEmpty(id)) {
			return new ApiResult(HttpResultEnum.MIS_PARAM.getCode(), HttpResultEnum.MIS_PARAM.getMessage());
		}
		try {
			return managerInfoService.delLobour(id);
		} catch (Exception e) {
			e.printStackTrace();
			return new ApiResult(HttpResultEnum.EXCEPTION.getCode(), HttpResultEnum.EXCEPTION.getMessage());
		}
	}

	/**
	 * 更新保险信息
	 *
	 * @return
	 */
	@RequestMapping(value = "updateLabour")
	@ResponseBody
	public ApiResult updateLabour(HttpServletRequest request, String object, String labor_type) {
		long beamId = super.getBeamId(request);
		long userId = super.getUserId(request);
		if (StringUtils.isNotEmpty(object) || StringUtils.isNotEmpty(labor_type)) {
			return new ApiResult(HttpResultEnum.MIS_PARAM.getCode(), HttpResultEnum.MIS_PARAM.getMessage());
		}
		ApiResult apiResult = null;
		try {
			Labour labour = JSON.parseObject(object, Labour.class);
			if (labour.getId() == null || labour.getId() == 0L) {
				return new ApiResult(HttpResultEnum.MIS_PARAM.getCode(), HttpResultEnum.MIS_PARAM.getMessage());
			}
			labour.setLabor_type(labor_type);
			apiResult = managerInfoService.updateLabour(labour, beamId, userId);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return apiResult;
	}

	/**
	 * 获取所有健康信息
	 *
	 * @return
	 */
	@RequestMapping(value = "getAllHealthList")
	@ResponseBody
	public PageResult getAllHealthList(HttpServletRequest request, long offset, int limit, String ecode, String name, String presasg) {
		long beamId = super.getBeamId(request);
		long userId = super.getUserId(request);
		PageResult healthList = managerInfoService.getHealthList(offset, limit, ecode, name, presasg, beamId);
		return healthList;
	}

	@RequestMapping("getHealthDetailInfo")
	@ResponseBody
	public ApiResult getHealthDetailInfo(String ecode, HttpServletRequest request) {
		long beamId = super.getBeamId(request);
		return managerInfoService.getHealthDetail(ecode, beamId);
	}

	/**
	 * 删除健康信息
	 */
	@RequestMapping("delHealthById")
	@ResponseBody
	public ApiResult delHealthById(long id) {

		return managerInfoService.delHealthByid(id);
	}

	/**
	 * 获取体检列表
	 */
	@RequestMapping("getMedical")
	@ResponseBody
	public PageResult getMedical(String ecode, long offset, int limit, HttpServletRequest request) {
		long beamId = super.getBeamId(request);
		return managerInfoService.getMedical(ecode, offset, limit, beamId);
	}

	/**
	 * 获取人员保险数据
	 *
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "/readLabourData", method = RequestMethod.GET)
	@ResponseBody
	public PageResult readLabourData(HttpServletRequest request) {
		long beamId = super.getBeamId(request);
		String offset = request.getParameter("offset");
		String limit = request.getParameter("limit");
		String ecode = request.getParameter("ecode");
		String name = request.getParameter("name");
		List<Labour> labourList = managerInfoService.readLabourData(beamId, offset, limit, ecode, name);
		long total = managerInfoService.countLabourData(beamId, ecode, name);
		return new PageResult(total, CommonUtils.parseLong(offset, 0L), labourList);
	}

	/**
	 * 获取一个保险数据
	 *
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "/getOneLabour", method = RequestMethod.GET)
	@ResponseBody
	public ApiResult getOneLabour(HttpServletRequest request) {
		String id = request.getParameter("id");
		if (StringUtils.isEmpty(id)) {
			return new ApiResult(HttpResultEnum.MIS_PARAM.getCode(), HttpResultEnum.MIS_PARAM.getMessage());
		}
		Labour oneLabour = managerInfoService.getOneLabour(id);
		return new ApiResult(oneLabour);
	}

	@RequestMapping("/getOccupationalValue")
	@ResponseBody
	public  ApiResult getOccupationalValue(HttpServletRequest request,String code){
		long beamId = super.getBeamId(request);
		String valueByCode = managerInfoService.getValueByCode(code, beamId);
		ApiResult apiResult=new ApiResult();
		apiResult.setResult(valueByCode);
		return apiResult;
	}

	/**
	 * 获取人员变动记录
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "/readStaffAdjustment", method = RequestMethod.GET)
	@ResponseBody
	public PageResult readStaffAdjustment(HttpServletRequest request){
		Long beamId = super.getBeamId(request);
		String offset = request.getParameter("offset");
		String limit = request.getParameter("limit");
		String ecode = request.getParameter("ecode");
		return managerInfoService.readStaffAdjustment(ecode, beamId, offset, limit);
	}

	/**
	 * 人员变动
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "/doStaffAdjustment", method = RequestMethod.POST)
	@ResponseBody
	public ApiResult doStaffAdjustment(HttpServletRequest request){
		String id = request.getParameter("id");
		String type = request.getParameter("type");
		String acBemaId = request.getParameter("acBemaId");
		Long beamId = super.getBeamId(request);
		Long userId = super.getUserId(request);
		if(StringUtils.isBlank(id) || StringUtils.isBlank(type) || StringUtils.isBlank(acBemaId)){
			return new ApiResult(HttpResultEnum.MIS_PARAM.getCode(), HttpResultEnum.MIS_PARAM.getMessage());
		}
		try{
			return managerInfoService.doStaffAdjustment(id, type, acBemaId, beamId, userId);
		}catch (Exception e){
			e.printStackTrace();
			return new ApiResult(HttpResultEnum.EXCEPTION.getCode(), HttpResultEnum.EXCEPTION.getMessage());
		}
	}
}
